import { handleLocalStorage } from './localstorage.js'

let currentCourseStatus

export function setCurrentCourseStatus(status) {
  currentCourseStatus = status
}

export function modifyCourseStatus(courseId, finishStatus, lockStatus) {
  currentCourseStatus = JSON.parse(
    handleLocalStorage('get', 'currentCourseStatus')
  )
  // 1、设置参数
  let currentFinishStatus = currentCourseStatus[courseId - 1].finish_status
  let currentLockStatus = currentCourseStatus[courseId - 1]
  let modifyCourseStatusParam = {
    courseID: courseId,
    'course_finish_status.storyLeading':
      currentFinishStatus.story_finish === true
        ? true
        : finishStatus.story_finish,
    'course_finish_status.pincipleLeading':
      currentFinishStatus.principle_finish === true
        ? true
        : finishStatus.principle_finish,
    'course_finish_status.labor':
      currentFinishStatus.labor_finish === true
        ? true
        : finishStatus.labor_finish,
    'course_finish_status.courseReport':
      currentFinishStatus.report_finish === true
        ? true
        : finishStatus.report_finish,
    // false 不加锁 true 加锁
    'lock_status.second_lock':
      currentLockStatus.second_lock === false ? false : lockStatus.second_lock,
    'lock_status.third_lock':
      currentLockStatus.third_lock === false ? false : lockStatus.third_lock,
    'lock_status.fourth_lock':
      currentLockStatus.fourth_lock === false ? false : lockStatus.fourth_lock,
  }
  // 2、调用接口
  console.log('接口参数', modifyCourseStatusParam)
  $.ajax({
    type: 'POST',
    url: 'http://donghao.fun:8080/modifyCourseInfoByUserID',
    data: modifyCourseStatusParam,
    success: function (response) {
      console.log(response)
    },
  })
}
